#include"comm.hpp"



int main()
{


    key_t k = getKey();
    printf("key : 0x%x\n",k);
    int shmid = getShm(k);
    printf("shmid : %d\n",shmid);
    

    //关联,挂接
    char* start = (char*)attchShm(shmid);
    printf("attch success, address start%p\n",start);

    const char* message = "hello server,我是另一个进程，我正在和你通信";
    pid_t id = getpid();
    int cnt = 1;
    // char buffer[1024];

    

    int wfd = open(NAME_PIPE,O_WRONLY);
    assert(wfd > 0);


    while(true)
    {
        sleep(5);
        //message,id,cnt
        // snprintf(buffer,sizeof(buffer),"%s[pid:%d][信息编号:%d]",message,id,cnt++);
        // memcpy(start,buffer,strlen(buffer)+1);
        snprintf(start,MAX_SIZE,"%s[pid:%d][信息编号:%d]",message,id,cnt++);
        //当这里信息发送到共享内存的时候，往命令管道发送一个数字1
        int code = 1;
        ssize_t n = write(wfd,&code,sizeof(code));
        assert(n == sizeof(int));
        printf("client -> server : 1\n");
    }

    close(wfd);

    detachShm(start);



    //done

    //这里就没必要删内存了

    return 0;
}
